package model

import (
	"dc-go/global"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type RequestPage struct {
	Page     int `json:"page" form:"page"`
	PageSize int `json:"page_size" form:"pageSize"`
}

type RequestSort struct {
	SortBy string `json:"sort_by" form:"sortBy"`
	Desc   bool   `json:"desc" form:"desc"`
}

type RequestPageAndSort struct {
	RequestPage
	RequestSort
}

type RequestAdd struct {
	Sort   uint   `json:"sort"`
	Status string `json:"status"`
	Memo   string `json:"memo"`
}

type RequestQueryById struct {
	Id uint `json:"id"`
}

type RequestQueryBySqlCode struct {
	SqlCode string `json:"sql_code"`
}

type RequestQueryBySqlparamCode struct {
	SqlparamCode string `json:"sqlparam_code"`
	Constraint   string `json:"constraint"`
}

type RequestSqlparams struct {
	SqlparamCode string `json:"sqlparam_code"`
	SqlparamName string `json:"sqlparam_name"`
	Value        string `json:"value"`
}

type RequestValidateVariable struct {
	VariableString string `json:"variable_string"`
}

type RequestQueryBySqlCodeAndParams struct {
	SqlCode string             `json:"sql_code"`
	Params  []RequestSqlparams `json:"params"`
}

type RequestQueryDirectSql struct {
	Sql string `json:"sql"`
}

type RequestQueryByEmpeeAcct struct {
	EmpeeAcct string `json:"empee_acct"`
}

func RequestShouldBindJSON(c *gin.Context, obj interface{}) error {
	if err := c.ShouldBindJSON(obj); err != nil {
		global.DcLogger.Error(global.DcConfig.System.BindError, zap.Any("err", err))
		ResponseErrorMessage(global.DcConfig.System.BindError+err.Error(), c)
		return err
	}
	return nil
}
